import pandas as pd
import warnings
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import SGDClassifier
import joblib
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import LabelEncoder
from xgboost import XGBClassifier
from sklearn.metrics import accuracy_score
from sklearn.linear_model import Perceptron
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
warnings.filterwarnings('ignore')

df = pd.read_csv('data/newmbti.csv')

le = LabelEncoder()
y = le.fit_transform(df['type'])

tfidf = TfidfVectorizer(stop_words='english')
X = tfidf.fit_transform(df['cleaned_post'])

X_train, X_test, y_train, y_test = train_test_split(X, df['type'], 
                                                    stratify=df['type'],
                                                    test_size=0.2,
                                                    random_state=123)
model = KNeighborsClassifier(n_neighbors=5)
model.fit(X_train, y_train)

print("Accuracy %s" %accuracy_score(y_test, model.predict(X_test)))

